﻿using System.Collections.Generic;
using System.Linq;

namespace PeiYue.Model.Dto.Sys
{
    public class SearchDicHeaderDto : BaseRequestDto
    { public string codec { get; set; } }
    public class DicHeaderDto
    {
        public long id { get; set; }
        /// <summary>
        /// 字典代码
        /// </summary>
        public string codec { get; set; }
        /// <summary>
        /// 字典名称
        /// </summary>
        public string namec { get; set; }
        /// <summary>
        /// 数据类型
        /// </summary>
        public int data_types { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string remark { get; set; }
        public List<DicDetailDto> details { get; set; }

        public void Add(List<DicDetailDto> dtoList)
        {
            if (details == null)
            {
                details = new List<DicDetailDto>();
            }
            details = dtoList;
        }
        public DicDetailDto GetDetail(string key)
        {
            if (details != null)
            {
                return details.Where(p => p.k == key).FirstOrDefault();
            }
            return null;
        }
        public DicDetailDto GetDetailByVal(string val)
        {
            if (details != null)
            {
                return details.Where(p => p.v == val).FirstOrDefault();
            }
            return null;
        }
        public List<SelectItemDto> ToSelectList()
        {
            var list = new List<SelectItemDto>();
            if (details != null)
            {
                foreach (var detail in details)
                {
                    list.Add(detail.ToSelectItem());
                }
            }
            return list;
        }
    }
}
